$loop_count = 0

def tarai(x, y, z)
    $loop_count += 1

    (y < x \
     ? tarai(tarai(x-1, y, z), tarai(y-1, z, x), tarai(z-1, x, y)) \
     : y)

    #if y < x
    #    return tarai(tarai(x-1, y, z), tarai(y-1, z, x), tarai(z-1, x, y))
    #end
    #return y
end

puts tarai(12, 6, 0)
puts $loop_count
